<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link
	href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet" type="text/css"
	href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;基础信息管理>打款名单维护</span>
		</div>
		<div class="ibox-content">
			<button type="button" class="btn dpbtn_green" onclick="add();">新增</button>
			<button type="button" class="btn dpbtn_red" onclick="del();">删除</button>
		</div>
		<div class="ibox-content">
			<div role="form" class="form-inline">
				<div class="form-group">
					<input type="text" placeholder="请输入机构" id="orgNameSearch"
						name="orgNameSearch" class="form-control"> <input
						type="text" placeholder="请输入账户编号" id="accounnNo" name="accounnNo"
						class="form-control">
				</div>
				<button class="zhixcx" type="button" onclick="query();">执行查询</button>
			</div>
		</div>
		<div class="ibox-content">
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>

	<div class="ibox-content" id="orghidden" style="display: none">
		<form class="form-horizontal m-t" id="commentForm">
			<div class="form-group">
				<label class="col-sm-3 control-label">机构名称：</label>
				<div class="col-sm-8">
					<input type="hidden" id="orgId" name="orgId" /> <input
						type="hidden" id="orgCode" name="orgCode" /> <input id="orgName"
						name="orgName" readonly="readonly" type="text"
						class="form-control smalliconcur smallicon" required=""
						placeholder="机构名称(必填)" onclick="choseOrg();" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">打款银行：</label>
				<div class="col-sm-8">
					<select class="select-control" id="bankId" name="bankId">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">资金渠道：</label>
				<div class="col-sm-8">
					<select class="select-control" id="fundChannel" name="fundChannel">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">帐户：</label>
				<div class="col-sm-8">
					<input id="accounnNo" name="accounnNo" type="text"
						class="form-control" required="" aria-required="true"
						placeholder="请输入用户账户(必填)">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">帐户名称：</label>
				<div class="col-sm-8">
					<input id="accountName" name="accountName" type="text"
						class="form-control" required="" aria-required="true"
						placeholder="请输入账户名称(必填)">
				</div>
			</div>
			<table cellpadding="0" cellspacing="0" border="0" bordercolor="#3B95C8" width="100%">
				<tr>
					<td width="100%" align="center">
						<div class="ibox-content">
							<button class="btn dpbtn_blue" type="button" onclick="save();">提交</button>
							<button class="btn dpbtn_green" type="button" onclick="closeLayer();">关闭</button>
						</div>
					</td>
				</tr>
			</table>
		</form>
	</div>

	<div class="ibox-content" id="orghiddenb" style="display: none">
		<form class="form-horizontal m-t" id="commentFormb">
			<div class="form-group">
				<label class="col-sm-3 control-label">机构名称：</label>
				<div class="col-sm-8">
					<input type="hidden" id="idb" name="id" /> <input type="hidden"
						id="orgIdb" name="orgId" /> <input id="orgNameb" name="orgName"
						readonly="readonly" type="text"
						class="form-control smalliconcur smallicon" required=""
						placeholder="机构名称(必填)" onclick="choseOrg();" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">打款银行：</label>
				<div class="col-sm-8">
					<select class="select-control" id="bankIdb" name="bankId">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">资金渠道：</label>
				<div class="col-sm-8">
					<select class="select-control" id="fundChannelb" name="fundChannel">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">帐户：</label>
				<div class="col-sm-8">
					<input id="accounnNob" name="accounnNo" type="text"
						class="form-control" required="" aria-required="true"
						placeholder="请输入用户账户(必填)">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">帐户名称：</label>
				<div class="col-sm-8">
					<input id="accountNameb" name="accountName" type="text"
						class="form-control" required="" aria-required="true"
						placeholder="请输入账户名称(必填)">
				</div>
			</div>
			<table cellpadding="0" cellspacing="0" border="0" bordercolor="#3B95C8" width="100%">
				<tr>
					<td width="100%" align="center">
						<div class="ibox-content">
							<button class="btn dpbtn_blue" type="button" onclick="doUpdate();">修改</button>
					<button class="btn dpbtn_green" type="button" onclick="closeLayer();">关闭</button>
						</div>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>

	<!-- custom js -->
	<%@include
		file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>
	<script type="text/javascript"
		src="${basePath}/js/zTreeStyle/jquery.ztree.core.js" charset="utf-8"></script>
	<script type="text/javascript"
		src="${basePath}/js/zTreeStyle/jquery.ztree.excheck.js"
		charset="utf-8"></script>

	<!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
	<script type="text/javascript">
    
		var winWidth = $(window).width();
		var winHeight = $(window).height();
		var lastSel;
	    jQuery(function($) {  
	    	getData();
	    	zjqd();
	    });
	    function zjqd(){
	    	show:false,
	    	$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{
	 				"parentValue":"Fund_Channel"
	 			},
	 			success: function(datas){
	 				  if(datas.flag == "100100")
						  {
		 					  var result = datas.result.rows;
		 					  var programme_sel=[];
		 				      for(var i=0;i<result.length;i++){
		 				          var programme = result[i];
		 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
		 				      }
		 				     $("#fundChannel").html(programme_sel.join(' '));
		 				    $("#fundChannelb").html(programme_sel.join(' '));
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	              }
		    	});
	    }
	    $(function(){
	    	show:false,
			$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{
	 				"parentValue":"Bank"
	 			},
	 			success: function(datas){
	 				  if(datas.flag == "100100")
						  {
		 					  var result = datas.result.rows;
		 					  var programme_sel=[];
		 				      for(var i=0;i<result.length;i++){
		 				          var programme = result[i];
		 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
		 				      }
		 				     $("#bankId").html(programme_sel.join(' '));
		 				     $("#bankIdb").html(programme_sel.join(' '));
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	              }
		    	});
		 });
	    
	    var changelayer;
	    var getData = function()
	    {
	  var winWidth = $('div.ibox-content').width();
	   	    winHeight = document.body.offsetHeight - 400;
		    var win = winWidth / 7 - 20;
  	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
		  jQuery("#table_list_1").jqGrid
		  ({
			show:false,
	        url:'${basePath}/BaseRemitAccountController/selectMuiltList',
	        datatype : "json",
	        colNames : [ '编号', '机构id','银行Id','资金渠道','组织名称', '银行名称', '账户名称','帐户编号','资金渠道'],
	        colModel : [ 
	                     {name: 'replaceId',index: 'id',hidden:true},
	                     {name: 'orgId',index: 'orgId',hidden:true},
	                     {name: 'bankId',index: 'bankId',hidden:true},
	                     {name: 'fundChannel',index: 'fundChannel',hidden:true},
	                  	 {name: 'orgName',index: 'orgName',width: win,align: "center",sorttype: "float"},
	               		 {name: 'bankLoanDisplay',index: 'bankLoanDisplay',width: win,align: "center",sorttype: "float"},
	            		 {name: 'accountName',index: 'accountName',width: win,align: "center",sorttype: "float"},
	               		 {name: 'accounnNo',index: 'accounnNo',width: win,align: "center",sorttype: "float"},
	               		{name: 'fundChannelDisplay',index: 'fundChannel',width: win,align: "center",sorttype: "float"}
	                   ],
              mtype : "post",
              height: winHeight,
              width:winWidth,  
              autowidth: true,
              shrinkToFit: true,
              rowNum: 15,
	           rowList: [15, 30, 45],
              viewrecords: true,
              pager: "#pager_list_1",
              hidegrid: false,
              multiselect : true,		//实现单选    multiboxonly:true   beforeSelectRow: true,
              multiboxonly:false,  
              beforeSelectRow: false,
              altRows:true,
              altclass:'someClass',
              ondblClickRow:function(rowId,v,e)
              {
  	          	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
  	          	  var id = rowData.replaceId;
  	          	  var orgId = rowData.orgId;
  	          	  var orgNameb = rowData.orgName;
  	          	  var bankIdb = rowData.bankId;
  	          	  var accounnNob = rowData.accounnNo;
  	          	  var accounnNameb = rowData.accountName;
  	          	  var fundChannelb=rowData.fundChannel;
  	          	  document.getElementById("idb").value=id;
  	          	  document.getElementById("orgIdb").value=orgId;
  	          	  document.getElementById("orgNameb").value=orgNameb;
  	          	  document.getElementById("bankIdb").value=bankIdb;	
  	          	  document.getElementById("accounnNob").value=accounnNob;
  	          	  document.getElementById("accountNameb").value=accounnNameb;
  	          	  document.getElementById("fundChannelb").value=fundChannelb;
  	          	  changelayer=layer.open({
			    	  title:'打款信息修改',
			    	  type: 1,
			    	  area: ['400px', '450px'], //宽高
		   			  content: $('#orghiddenb')
			    	});
  	          	  
              },
	         jsonReader: {
	                root: "result.rows",
	                page: "result.page",
	                total: "result.total",
	                records: "result.records",
	                repeatitems: false,
	                id: "replaceId"
	          },
	          loadComplete:function(datas){
	        	  if (datas.flag == "100100") {
	                  layer.msg("查询成功!", {icon: 6, time: 1000});
	                  return;
	              }
	        	  if(datas.flag == '100802') {
					  top.location.href = thisLoginUrl;
					  return;
				  }

	        	  layer.msg(datas.message, {icon: 2});
	          }
	      });
	    }
	    
	    
	    function closeLayer(){
	    	layer.closeAll();
	    }
	    
	    window.onresize = function()
	    {
	    	 $("#table_list_1").setGridWidth($(window).width()-80);
	    	 $("#table_list_1").setGridHeight($(window).height() / 2.5);
	    }
	    
	    //搜索
	    var query = function()
	    {
	    	var accounnNo = document.getElementById("accounnNo").value.trim();
	    	$("#table_list_1").jqGrid("setGridParam",{
	    		url:'${basePath}/BaseRemitAccountController/selectMuiltList',
   				postData:{
   		        	"accounnNo":accounnNo,
   		        	"orgName":$("#orgNameSearch").val()
   		        },
   				datatype:"json"
	    	}).trigger("reloadGrid")
	    }
	    
	    var addlayer;
	    var add = function()
	    {
	    	addlayer= layer.open({
	    	  title:'打款名单添加',
	    	  type: 1,
	    	  area: ['400px', '450px'], //宽高
	    	  content: $("#orghidden"),
	    	  end: function () {
	                refresh();
	            }
	    	});
	    }
	    var choseOrg=function(){
	    	$.dpAjax({
	    		url:'${basePath}/BaseBusiUnitController/list',
	    		data:{dpStatus:1},
    			success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  var content = '<div class="ibox-content" style="height: 280px;border: 1px solid #F5F5F6; overflow:auto;overflow-x: hidden;">'
	    						+ '	<div id="orgTree" class="ztree">&nbsp;</div>'
	    					+ '</div>'
	    					+ '<div class="ibox-content">'
	    					+ '	 <button class="btn dpbtn_green" type="button" onclick="confirmPower();">确定</button>'
	    					+ '</div>';

	    				index = layer.open({
	    					  title:'机构列表',
	    					  type: 1,
	    					  area: ['300px', '380px'], //宽高
	    					  content: content
	    				});
				    	var setting = {
			 					check: {
			 						enable: false
			 					},
			 					data: {
			 						simpleData: {
			 							enable: true
			 						}
			 					}
			 			 };			
    				  var zNodes = datas.result.rows;
    				  var list=[];
    				  for(var i=0;i<datas.result.rows.length;i++){
	    				  var obj=new Object();
    					  obj.id=datas.result.rows[i].replaceId;
    					  obj.name=datas.result.rows[i].orgName;
    					  obj.pId=datas.result.rows[i].parentId;
    					  obj.unitCode=datas.result.rows[i].orgCode;
    					  if(datas.result.rows[i].replaceId == 1){
    						  obj.open = true;
     					  } else {
     						 obj.open = false; 
     					  }
    					  list.push(obj);
    				  }
    				  $.fn.zTree.init($("#orgTree"), setting, list);
					  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
                 }
	    	});
	    }
	    
	    var confirmPower = function()
	    {
	    	 var zTree = $.fn.zTree.getZTreeObj("orgTree"); 
	    	 var node=zTree.getSelectedNodes();
	    	 var treeNode = node[0];
	    	 var replaceId = treeNode.id;
	    	 if(replaceId == 1)
			  {
				  layer.msg('顶级节点无法选择！', {icon: 5});
				  return;
			  }
	    	 if(""!=node && node.length>0){
		    	 document.getElementById("orgName").value=node[0].name;
		    	 document.getElementById("orgCode").value=node[0].unitCode;
		    	 document.getElementById("orgId").value=node[0].id;
		    	 document.getElementById("orgNameb").value=node[0].name;
		    	 document.getElementById("orgIdb").value=node[0].id;
		    	 layer.close(index);
	    	 }
	    }
	    var flag=false;
	    var save = function()
	    {
	    	var validstatus = $("#commentForm").valid();
	    	
	    	if(validstatus)
	    	{
	    		var data = $('#commentForm').serialize();
	    		$.dpAjax({
		    		url:'${basePath}/BaseRemitAccountController/save',
		    		data:data,
	    			success: function(datas){
		    			  if(datas.flag == "100100")
						  {
							  layer.close(addlayer);
							  return;
						  }
		    			  if(datas.flag == "101902"){
		    				  layer.msg('同一地区下只能有一个资金渠道！', {icon: 5});
							  layer.close(addlayer);
							  return;
		    			  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	                 }
		    	});
	    	}
	    }
	    var del = function()
	    {
	    	var rowData = jQuery('#table_list_1').jqGrid('getGridParam','selarrrow');  
	    	if(rowData.length < 1)
	    	{  
	    		layer.msg("请选择要删除的数据信息！", {icon: 5});
				return;
	    	}
	    	
	    	
	    	for(var i=0;i<rowData.length;i++)
	    	{
	    		var mainId = jQuery('#table_list_1').jqGrid('getCell',rowData[i],'replaceId'); 
    			layer.confirm('您确认要删除吗？', {
    			  btn: ['确定','取消'] //按钮
    			},function(){
    				layer.closeAll();
    				$.dpAjax({
    		    		url:'${basePath}/BaseRemitAccountController/remove',
    	    			data:{"id":mainId},
    	    			success: function(datas){
    	    			  if(datas.flag == "100100")
  						  {
  							  layer.msg('执行成功！', {icon: 6});
  							  refresh();
  							  return;
  						  }
  						  if(datas.flag == "100200")
  		                  {
  							  $.fn.showDatas({"datas":datas});
  		                	  return;
  		                  }
  						  layer.msg(datas.message, {icon: 2});
    	                }
    		    	});
    			});
	    	}
	    }
	    
	    
	     var doUpdate=function(){
    		var data = $('#commentFormb').serialize();
    		$.dpAjax({
	    		url:'${basePath}/BaseRemitAccountController/modify',
	    		data:data,
    			success: function(datas){
	    			  if(datas.flag == "100100")
					  {
						  layer.close(changelayer);
						  refresh();
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
					  layer.msg(datas.message, {icon: 2});
                 }
	    	});
	    }
	     
	    var refresh = function () {
	        $("#table_list_1").jqGrid("setGridParam", {search: true}).trigger("reloadGrid", [{page: 1}]);
	    }
	    
	    $(function(){
	  		// 验证
	  	        $("#commentForm").validate({
	  	            //重写showErrors
	  	            showErrors: function (errorMap, errorList) {
	  	                
	  	                $.each(errorList, function (i, v) {
	  	                    layer.tips(v.message, v.element, { time: 1500 });
	  	                    return false;
	  	                });  
	  	            },
	  	            /* 失去焦点时验证 */
	  	            onfocusout: function(element) { $(element).valid(); },
	  	            /*  键盘抬起不验证 */
	  	            onkeyup:false,
	  	        })
	  	        
	  	        $("#commentFormb").validate({
	  	            //重写showErrors
	  	            showErrors: function (errorMap, errorList) {
	  	                
	  	                $.each(errorList, function (i, v) {
	  	                    layer.tips(v.message, v.element, { time: 1500 });
	  	                    return false;
	  	                });  
	  	            },
	  	            /* 失去焦点时验证 */
	  	            onfocusout: function(element) { $(element).valid(); },
	  	            /*  键盘抬起不验证 */
	  	            onkeyup:false,
	  	        })
		    });
	    
	    var cancelPower = function()
	    {
	    	
	    }
    </script>
</body>
</html>
